home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / ibus / lang.py < prev    next >
Text File  |  2009-11-05  |  2KB  |  76 lines

  1. # vim:set et sts=4 sw=4:
  2. #
  3. # ibus - The Input Bus
  4. #
  5. # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this program; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. # Boston, MA  02111-1307  USA
  21.  
  22. __all__ = (
  23.         "get_language_name",
  24.     )
  25.  
  26. import xml.parsers.expat
  27. import locale
  28. import gettext
  29.  
  30. _ = lambda a: gettext.dgettext("ibus", a)
  31. __languages_dict = {}
  32.  
  33. def get_language_name(_locale):
  34.     lang = _locale.split("_")[0]
  35.     lang = lang.lower()
  36.     if lang in __languages_dict:
  37.         lang = __languages_dict[lang]
  38.         lang = gettext.dgettext("iso_639", lang)
  39.     else:
  40.         lang = _(u"Other")
  41.         lang = gettext.dgettext("ibus", lang)
  42.     return lang
  43.  
  44. def __start_element(name, attrs):
  45.     global __languages_dict
  46.     try:
  47.         name = attrs[u"name"]
  48.         for attr_name in (u"iso_639_2B_code", u"iso_639_2T_code", u"iso_639_1_code"):
  49.             if attr_name in attrs:
  50.                 attr_value = attrs[attr_name]
  51.                 __languages_dict[attr_value] = name
  52.     except:
  53.         pass
  54.  
  55. def __end_element(name):
  56.     pass
  57.  
  58. def __char_data(data):
  59.     pass
  60.  
  61. def __load_lang():
  62.     iso_639_xml = "/usr/share/xml/iso-codes/iso_639.xml"
  63.     p = xml.parsers.expat.ParserCreate()
  64.     p.StartElementHandler = __start_element
  65.     p.EndElementHandler = __end_element
  66.     p.CharacterDataHandler = __char_data
  67.     p.ParseFile(file(iso_639_xml))
  68.  
  69. __load_lang()
  70.  
  71. if __name__ == "__main__":
  72.     print get_language_name("mai")
  73.     print get_language_name("zh")
  74.     print get_language_name("ja")
  75.     print get_language_name("ko")
  76.